﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test16
{
    class Program
    {
        static void Main(string[] args)
        {
            //完成AdoNet两种获取数据的方法；
            //完成增加、删除、更新的方法的演练；

            var constring = "server=.;database=Sudents;uid=sa;pwd=030824";
            SqlConnection connection = new SqlConnection(constring);
            connection.Open();


            var com = "select * from Student";
            SqlCommand command = new SqlCommand(com, connection);
            var reader = command.ExecuteReader();


            Console.WriteLine("{0}\t{1}\t{2}\t{3}", "学号", "姓名", "年龄", "性别");
            while (reader .Read ())
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}",reader ["Id"], reader["Name"], reader["Age"], reader["Sex"]);
            }
            reader.Close();


            command.CommandText = "insert into Student(Id,Name,Age ,Sex) values (7,'小葵',5,'男')";
            command.ExecuteNonQuery();

            command.ExecuteNonQuery();
            command.CommandText = "delete Student where id=4";

            command.CommandText = "update Student set Name='大奎',Sex='男',where id=6";
            command.ExecuteNonQuery();
        }
    }
}
